#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n,i,k,len;
    char s[10009],c;
    cin>>n;
    while(n--)
    {
        scanf("%s",s);
        //cin>>s;
        len=strlen(s);
        i=0;
        while(i<len)
        {
            k=i; c=s[i];
            while(s[i]==c &&i<len) i++;
            if(i-k>1) cout<<i-k;
            cout<<s[k];
        }
        cout<<endl;
    }
    return 0;
}
